<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var nodes = {};
	$(function() {
		$('#tree').tree({url : 'tree.do',animate:true
			,formatter:function(node){
				nodes[node.id] = node;
                var html = '<a href="javascript:void(0)" onclick="toEdit(\''+node.id+'\')" class="node-opt">' + node.text + '</a>';
                if (node.wings) {
                	html += '<span style="margin-left:10px;margin-right:5px;">：</span>';
                	var wing;
                	for(var i = 0; i < node.wings.length; i++) {
                		wing = node.wings[i];
                		nodes[wing.id] = wing;
                		html += '<a href="javascript:void(0)" onclick="toEdit(\''+wing.id+'\')" class="wing-opt">' + wing.text + '</a>';
                	}
                }
                return html;
            }
			,onBeforeSelect:function(node){return false;}
		});
	});
	
	function toEdit(id) {
		var node = nodes[id];
		var data = {id:node.id,name:node.text,index:node.attributes&&node.attributes.index?node.attributes.index:1};
		$('#dataform').form('clear').form('load',data);
		$('#dialog').dialog('open').dialog('center');
	}
	
	function save() {
		$.submit('#dataform',function(r) {
			if(r.code<0) return $alert(r.msg);
			$('#dialog').dialog('close');
			$('#tree').tree('reload');
			$prompt('保存成功');
		});
	}
</script>
</head>
<body>
	<div id="tree"></div>
	<div id="dialog" class="easyui-dialog" data-options="title:'功能信息',iconCls:'icon-module',closed:true,modal:true,width:500,height:250,buttons:[{iconCls:'icon-save',text:'保存',handler:save}]">
	<form id="dataform" action="save.do" method="post">
		<input type="hidden" name="id" />
		<table class="form-tbl">
			<tr class="form-tr">
				<th class="form-th">功能名称：</th>
				<td class="form-td required">
					<input type="text" name="name" class="easyui-validatebox form-text" data-options="required:true" />
				</td>
			</tr>
			<tr class="form-tr">
				<th class="form-th">功能排序：</th>
				<td class="form-td required">
					<input type="text" name="index" class="easyui-numberbox" style="width:50px;" data-options="required:true,precision:0,min:1" />
				</td>
			</tr>
		</table>
		</form>
	</div>
</body>
</html>